#include <iostream>
using namespace std;
void main()
{
	int m,n,r;
	cin>>m;
	cin>>n;
	r=m%n;
	while(r!=0)
	{
		m=n;
		n=r;
		r=m%n;
	};
	cout<<n<<endl;
}